﻿using System;
using Pap.Data;

namespace Pap.Web.Utils
{
    /// <summary>
    /// 
    /// </summary>
    [Serializable]
    public class InMemoryImage : IImage
    {
        /// <summary>
        /// Gets or sets the image ID.
        /// </summary>
        /// <value>
        /// The image ID.
        /// </value>
        public Guid ImageID
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the image data.
        /// </summary>
        /// <value>
        /// The image data.
        /// </value>
        public byte[] ImageData
        {
            get;
            set;
        }

        /// <summary>
        /// Gets the type of the image.
        /// </summary>
        /// <value>
        /// The type of the image.
        /// </value>
        public ILookUpEntity ImageType
        {
            get { throw new NotImplementedException(); }
        }

        /// <summary>
        /// Gets or sets the image type ID.
        /// </summary>
        /// <value>
        /// The image type ID.
        /// </value>
        public Guid ImageTypeID
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the label.
        /// </summary>
        /// <value>
        /// The label.
        /// </value>
        public string Label
        {
            get;
            set;
        }

        /// <summary>
        /// Performs an explicit conversion from <see cref="Pap.Web.Utils.InMemoryImage"/> to <see cref="Pap.Data.Image"/>.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <returns>
        /// The result of the conversion.
        /// </returns>
        public static explicit operator Image(InMemoryImage image)
        {
            return new Image()
            {
                ImageData = image.ImageData,
                ImageID = image.ImageID,
                ImageTypeID = image.ImageTypeID,
                Label = image.Label
            };
        }

        /// <summary>
        /// Performs an explicit conversion from <see cref="Pap.Data.Image"/> to <see cref="Pap.Web.Utils.InMemoryImage"/>.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <returns>
        /// The result of the conversion.
        /// </returns>
        public static explicit operator InMemoryImage(Image image)
        {
            return new InMemoryImage()
            {
                ImageData = image.ImageData.ToArray(),
                ImageID = image.ImageID,
                ImageTypeID = image.ImageTypeID,
                Label = image.Label
            };
        }

    }
}